<?php

namespace App\Listeners;

use App\Events\OrderPaid;
use App\Services\CartService;
use Illuminate\Contracts\Queue\ShouldQueue;

// 删除对应的购物车信息
class RemoveCartItem implements ShouldQueue
{

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle(OrderPaid $event)
    {
        $order = $event->getOrder();
        $sku_ids = $order->items->pluck('product_sku_id')->toArray();
        (new CartService)->remove($sku_ids, $order->user_id);
    }
}
